package com.sample.activity;

import com.sample.logic.HttpStandardLogic;
import com.sample.activity.R;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * POST通信サンプル.(非同期通信)
 * @author SASAKI
 *
 */
public class HttpPostActivity extends Activity {

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // get_test.xmlを表示
        setContentView(R.layout.post_test);

        Button sendButton = (Button) findViewById(R.id.POST_btnSend);
        // Eventを実装
        sendButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				String param1 = ((EditText) findViewById(R.id.POST_etParam1)).getText().toString();
				String param2 = ((EditText) findViewById(R.id.POST_etParam02)).getText().toString();

				ASyncAction async = new ASyncAction();
				async.execute(param1, param2);
			}
		});
    }


    /**
     * 非同期通信を行うインナークラス.
     * @author SASAKI
     *
     */
    public class ASyncAction extends AsyncTask<String, Object, String> {

    	@Override
    	protected String doInBackground(String... params) {
			HttpStandardLogic logic = new HttpStandardLogic();
			String result = logic.sendHttpPost(params[0], params[1]);
    		return result;
    	}

    	@Override
    	protected void onPostExecute(String result) {
			TextView tvResult = (TextView) findViewById(R.id.POST_etResult);
			tvResult.setText(result);
    	}
    }
}